package com.share.lottery.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import com.share.lottery.R;
import com.share.lottery.adapter.ViewPagerAdapter;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;



/**
 * 
 * @{# GuideActivity.java Create on 2013-5-2 下午10:59:08
 * 
 *     class desc: 引导界面
 * 
 *     <p>
 *     Copyright: Copyright(c) 2013
 *     </p>
 * @Version 1.0
 * @Author <a href="mailto:gaolei_xj@163.com">Leo</a>
 * 
 * 
 */
public class GuideActivity extends Activity implements OnPageChangeListener {

	private ViewPager vp;
	private ViewPagerAdapter vpAdapter;
	private List<View> views;
	// 底部小点图片
	private ImageView[] dots;

	// 记录当前选中位置
	private int currentIndex;
	private List<ImageView> imageViews;
	private ImageView imageView;
	private ViewGroup group;
	
	private AtomicInteger what = new AtomicInteger(0);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guide);
		imageViews=new ArrayList<ImageView>();
		group=(ViewGroup) findViewById(R.id.viewGroup);
		// 初始化页面
		initViews();
	}

	private void initViews() {
		LayoutInflater inflater = LayoutInflater.from(this);

		views = new ArrayList<View>();
		// 初始化引导图片列表
		views.add(inflater.inflate(R.layout.what_new_one, null));
		views.add(inflater.inflate(R.layout.what_new_two, null));
		views.add(inflater.inflate(R.layout.what_new_three, null));
		
		// 初始化Adapter
		vpAdapter = new ViewPagerAdapter(views, this);
		vp = (ViewPager) findViewById(R.id.viewpager);
		vp.setAdapter(vpAdapter);
		// 绑定回调
		vp.setOnPageChangeListener(this);
//		initDots();
	}
//	public void initDots(){
//		for (int i = 0; i < views.size(); i++) {
//			imageView = new ImageView(this);
//			imageView.setLayoutParams(new LayoutParams(10, 10));
//			imageView.setPadding(5, 5, 5, 5);
//			if (i == 0) {
//				imageView.setBackgroundResource(R.drawable.banner_dian_focus);
//			} else {
//				imageView.setBackgroundResource(R.drawable.banner_dian_blur);
//			}
//			imageViews.add(imageView);
//			group.addView(imageView);
//		}
//	}

	// 当滑动状态改变时调用
	@Override
	public void onPageScrollStateChanged(int arg0) {
	}

	// 当当前页面被滑动时调用
	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	// 当新的页面被选中时调用
	@Override
	public void onPageSelected(int arg0) {
//		// 设置底部小点选中状态
//		what.getAndSet(arg0); // 获取出what的值并设置新的值
//		for (int i = 0; i < imageViews.size(); i++) {
//			if(arg0==i){
//				imageViews.get(arg0).setBackgroundResource(R.drawable.banner_dian_focus);
//			}else{
//				imageViews.get(i)
//				.setBackgroundResource(R.drawable.banner_dian_blur);
//			}
//		}
	}

}
